package manage.operation;

import manage.book.Book;
import manage.book.BookList;

import java.util.Scanner;

public class Borrow implements IO{
    public void work(BookList bookList){
        System.out.println("借阅图书");
        Scanner scan = new Scanner(System.in);

        System.out.println("请输入借阅的图书名：");
        String name = scan.nextLine();
        int currentSize = bookList.getUsedSize();
        boolean found = false;

        for (int i = 0; i < currentSize; i++) {
            Book book = bookList.getBook(i);
            if(book.getName().equals(name)){
                if(!book.isBorrowed()){//如果书没被借出去
                    book.setBorrowed(true);
                    System.out.println("借阅成功");
                } else {
                    System.out.println("该书已经被借出，无法借阅");
                }
                found = true;
                break;
            }
        }
        if(!found){
            System.out.println("没找到这本书，借阅失败");
        }
    }
}
